<?php
class Zendhlt_View_Helper_CmsBlock extends Zend_View_Helper_Abstract{
	
	public function cmsBlock($title, $html = null, $info = null, $option = 1) {
		
		$xhtml = '<div class="block">';
		$xhtml .= '<div class="title">';
		$xhtml .= '<span>' . $title . '</span>';
		if ($html != null) {
			$xhtml .= $html;
		}
		$xhtml .= '</div>';
		$xhtml .= '<div class="content">';
		if ($info != null) {
			switch ($option) {
				case 1: // Tin rao mới
					foreach ($info as $val) {
						$id = $val->id;
						$tieu_de = $val->tieu_de;
						$img = $val->hinh_anh;
						$dia_chi = $val->dia_chi;
						$dien_tich = $val->dien_tich;
						$hinh_anh = '/phong_tro/avatar/' . $img;
						if (preg_match("/(.*)[,](.*)/", $img)) {
							$list_image = explode (',', $img);
							$hinh_anh = '/phong_tro/avatar/' . $list_image[0];
						}
						$xhtml .= '<div class="sidebar-item">';
						$xhtml .= '<div class="metadata">';
						$xhtml .= '<img src="' . $this->view->baseUrl(PUBLIC_IMG_URL . $hinh_anh) . '" alt="' . $val->tieu_de . '" width="50px" height="50px" onerror="this.onerror=null; this.src=\'' . $this->view->baseUrl(PUBLIC_IMG_URL . '/phong_tro/avatar/error_avatar_home.png') . '\';" />';
						$xhtml .= '</div>';
						$xhtml .= '<a title="' . $tieu_de . '" rel="bookmark" href="/ptrtinrao/view/id/' . $id . '">' . Zendhlt_Encode::truncateString_($tieu_de, 30). '</a>';
						$xhtml .= '<div class="info">';
						$xhtml .= 'Địa chỉ: ' . Zendhlt_Encode::truncateString_($dia_chi, 20) . '<br />';
						$xhtml .= 'Diện tích: ' . $dien_tich . ' m<sup>2</sup><br />';
						$xhtml .= '</div>';
						$xhtml .= '</div>';
					};
					break;
				
				case 2: // Tin tức nổi bật
					foreach ($info as $val) {
						$id = $val->id;
						$tieu_de = $val->tieu_de;
						$hinh_anh 	= $this->view->baseUrl(NEWS_IMAGES_PATH . NEWS_IMAGE_PREFIX2 . '/' . NEWS_IMAGE_PREFIX2 . $val->hinh_anh);
						$gioi_thieu = $val->gioi_thieu;
						$xhtml .= '<div class="sidebar-item">';
						$xhtml .= '<div class="metadata">';
						$xhtml .= '<img src="' . $hinh_anh . '" alt="' . $val->tieu_de . '" width="50px" height="50px" onerror="this.onerror=null; this.src=\'' . $this->view->baseUrl(NEWS_IMAGES_PATH . 'error/50_50_news_default.png') . '\';" />';
						$xhtml .= '</div>';
						$xhtml .= '<a title="' . $tieu_de . '" rel="bookmark" href="/tintuc/view/id/' . $id . '">' . Zendhlt_Encode::truncateString_($tieu_de, 30) . '</a>';
						$xhtml .= '<div class="info">';
						$xhtml .= Zendhlt_Encode::truncateString_($gioi_thieu, 60);
						$xhtml .= '</div>';
						$xhtml .= '<div class="clear"></div>';
						$xhtml .= '</div>';
					};
					break;
					
				case 3: // Hỗ trợ trực tuyến
					$xhtml .= '<div class="row-item">';
					$nickname = explode ('-', $info['cty_nick_yahoo']);
					$xhtml .= '<a href="ymsgr:sendim?' . $nickname[0] . '" title="' . $nickname[1] . '">';
					$xhtml .= '<img border="0" src="http://opi.yahoo.com/online?u=' . $nickname[0] . '&m=g&t=2" alt="' . $nickname[1] . '" />';
					$xhtml .= '<span class="text-info nickname">' . $nickname[1] . '</span>';
					$xhtml .= '</a><div class="clear"></div>';
					$xhtml .= '</div>';
					$xhtml .= '<div class="row-item">';
					$nickname = explode ('-', $info['cty_nick_skype']);
					$xhtml .= '<a href="skype:' . $nickname[0] . '?chat" title="' . $nickname[1] . '">';
					$xhtml .= '<img style="width: 61%" src="http://mystatus.skype.com/bigclassic/' . $nickname[0] . '" title="' . $nickname[0] . '" title="' . $nickname[1] . '" />';
					$xhtml .= '<span style="margin-top: 8px" class="text-info nickname">' . $nickname[1] . '</span>';
					$xhtml .= '</a><div class="clear"></div>';
					$xhtml .= '</div>';
					$xhtml .= '<div class="row-item row-tel">';
					$xhtml .= '<div class="icon-tel"></div>';
					$xhtml .= '<div class="text-info tel">' . $info['cty_hotline'] . '</div>';
					$xhtml .= '<div class="clear"></div>';
					$xhtml .= '</div>';
					break;
					
				case 4: // Thống kê truy cập
					require_once 'BlockCounterHits.php';					
					$block = new BlockCounterHits();
					$xhtml .= $block->counter();
					$xhtml .= $block->counterMember();
					break;
			}
		}
		$xhtml .= '</div>';
		$xhtml .= '<br class="clear" /></div>';
		
		return $xhtml;
	}
}